package com.woniuxy.controller;

import com.github.pagehelper.PageInfo;
import com.woniuxy.entitys.TbHospitalManager;
import com.woniuxy.service.HospitalMangerService;
import com.woniuxy.utils.ResultVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @author wu
 * @date 2024/01/11 18:41:52
 */
@RestController
public class HospitalMangerConroller {
    @Autowired
    private HospitalMangerService hospitalMangerService;


    @PostMapping("getAllHospManger")
    public ResultVO getAllHospManger(@RequestBody Map<String,Object>map){
       String input = (String) map.get("input");
       Integer pageNum = (Integer) map.get("pageNum");
       Integer pageSize = (Integer) map.get("pageSize");
       PageInfo<TbHospitalManager> list = hospitalMangerService.getAllHospManger(input,pageNum,pageSize);
        return list!=null? ResultVO.success("查询负责人成功",list):ResultVO.failure("查询负责人失败");
    }
    @PostMapping("deleteMangerById")
    public ResultVO deleteMangerById(@RequestBody Map<String,Integer> map){
        Integer id = map.get("id");
        Integer flag = map.get("flag");
        int count = hospitalMangerService.deleteMangerById(id,flag);
        return count>0? ResultVO.success("删除负责人成功"):ResultVO.failure("删除负责人失败");
    }
    @GetMapping("resetPasswordById/{id}")
    public ResultVO resetPasswordById(@PathVariable("id") Integer id){
        int count = hospitalMangerService.resetPasswordById(id);
        return count>0? ResultVO.success("重置密码成功"):ResultVO.failure("重置密码失败");
    }
    @GetMapping("saveHospitalMer/{phone}")
    public ResultVO saveHospitalMer(@PathVariable("phone") String phone){
        int count = hospitalMangerService.saveHospitalMer(phone);
        return count>0? ResultVO.success("重置密码成功"):ResultVO.failure("重置密码失败");
    }
    @GetMapping("loadWorkerInfo")
    public ResultVO loadWorkerInfo(){
        TbHospitalManager tbHospitalManager = hospitalMangerService.loadWorkerInfo();
        return tbHospitalManager!=null? ResultVO.success("查找成功",tbHospitalManager):ResultVO.failure("查找失败");
    }
    @PostMapping("updHospMangerInfos")
    public ResultVO updHospMangerInfos(@RequestBody TbHospitalManager tbHospitalManager){
        int count = hospitalMangerService.updHospMangerInfos(tbHospitalManager);
        return count>0? ResultVO.success("修改成功"):ResultVO.failure("修改失败");
    }

}
